package mapper;

import com.gxh.javabean.User;
import com.gxh.javabean.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface UserMapper {
    List<User> selectAll();

    List<User> selectByUserOne(User user);
    List<User> selectByUser(User user);
    List<User> selectByUsernameAndPassword(@Param("username") String username,@Param("password") String password);

    @Select({"<script>        select * from user\n" +
            "            <where>\n" +
            "                <if test=\"uid!=0\"> and uid=#{uid}</if>\n" +
            "                <if test=\"username!=null\"> and username=#{username}</if>\n" +
            "                <if test=\"password!=null\"> and password=#{password}</if>\n" +
            "                <if test=\"phone!=null\"> and phone=#{phone}</if>\n" +
            "            </where></script> "})
    List<User> selectByUser1(User user);

    @Select("select * from user")
    @Results(id = "u_r",value = {
            @Result(id = true,column = "uid",property = "uid"),
            @Result(property = "r",column = "uid",one = @One(
                    select="mapper.RoleMapper.selectByUid",
                    fetchType = FetchType.LAZY
            ))
    })
    List<User> selectUser_Role();



}
